package com.filetransfer.view.Components.render;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
public class ShareCodeRender extends TextWithCopyButton implements TableCellRenderer {
    private final JLabel failureLabel;
    public ShareCodeRender() {
        super("");
        failureLabel = new JLabel("暂未获取");
        failureLabel.setHorizontalAlignment(SwingConstants.CENTER);
        failureLabel.setForeground(Color.RED);
        failureLabel.setOpaque(true);
    }
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value == null || value.toString().trim().isEmpty()) {
            failureLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
            return failureLabel;
        } else {
            setText(value.toString());
            setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
            return this;
        }
    }
}
